import db, {listOfItems} from '../../database/lowDB/connectDb.js';
import {autoIncreamentKey} from '../../utils/index.js'


class listOfItemsModel {
    constructor() {
        this.tableName = 'listOfItems';
    }

    // 根据事项分支id查询所有子元素
    async getListOfItemsByThingModelBranchId(thingModelBranchId) {
        return listOfItems.filter(item => item.thingModelBranchId === thingModelBranchId);
    }

    // 新增事项清单分支下的子元素  --单条新增
    async addListOfItems(listOfItemData) {
        const {userId,roleCode,thingModelId,thingModelBranchId,subTitle,status,content} = listOfItemData
        listOfItems.unshift({
            id:autoIncreamentKey(listOfItems),
            userId,
            roleCode,
            thingModelId,
            thingModelBranchId,
            itemName:subTitle,
            status:status,
            content:content
        })
        db.write()
        return true
    }
}   

export default new listOfItemsModel();